// SM3, GB/T 32905-2016 信息安全技术 SM3密码杂凑算法
// bobwxc@yeah.net, 2023
// Public domain

#ifndef SM3_H
#define SM3_H

#include <stdint.h>

#define SM3_HASH_DIGEST_SIZE 32 // bytes

#define SM3_HASH_BLOCK_SIZE 64 // bytes

void sm3_once_calcu(unsigned char *m, size_t bytes_length, unsigned char digest[32]);
void sm3_hexdigest(unsigned char digest[32], char hexdigest[64]);

typedef uint32_t SM3_Word; // stored in local endian

struct sm3
{
    unsigned char remaind_bytes[64];
    size_t remaind_bytes_length;
    size_t handled_bytes_length; // exclude the remainder_bytes
    SM3_Word Vi_sub1[8];
    SM3_Word Vn[8];
};

typedef struct sm3 sm3_t;

void sm3_init(sm3_t *hash_body);
void sm3_update(sm3_t *hash_body, unsigned char *m, size_t bytes_length);
void sm3_digest(sm3_t *hash_body, unsigned char digest[32]);

#endif // SM3_H